package com.holike.crm.bean;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.holike.crm.util.ParseUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pony on 2019/10/30.
 * Version v3.0 app报表
 * 经营目标数据
 */
public class BusinessObjectivesBean {
    public String type; //1 展示经营目标 2展示个人目标
    @SuppressWarnings("WeakerAccess")
    String isShop; //是否展示门店业绩
    @SuppressWarnings("WeakerAccess")
    String isPerson; //是否暂时个人业绩
    public String time;
    public String moneyTotal; //总目标
    public String countTotal; //总业绩
    String percent; //总百分比
    @SuppressWarnings("WeakerAccess")
    List<ShopDataBean> shopData;
    @SuppressWarnings("WeakerAccess")
    List<UserDataBean> userData;
    @SuppressWarnings("WeakerAccess")
    List<ShopSelectBean> shopSelect;
    @SuppressWarnings("WeakerAccess")
    List<PersonDataBean> personArr;

    public String getPercent() {
        if (TextUtils.isEmpty(percent)) return "0%";
        if (!percent.contains("%")) return percent + "%";
        return percent;
    }

    public double getPercentValue() {
        if (TextUtils.isEmpty(percent)) return 0;
        return ParseUtils.parseDouble(percent.replaceAll("%", "")) / 100;
    }

    public boolean isShop() {
        return TextUtils.equals(isShop, "1");
    }

    public boolean isPerson() {
        return TextUtils.equals(isPerson, "1");
    }

    public List<ShopDataBean> getShopData() {
        return shopData == null ? new ArrayList<>() : shopData;
    }

    public List<UserDataBean> getUserData() {
        return userData == null ? new ArrayList<>() : userData;
    }

    public List<ShopSelectBean> getShopSelect() {
        return shopSelect == null ? new ArrayList<>() : shopSelect;
    }

    public List<PersonDataBean> getPersonData() {
        return personArr == null ? new ArrayList<>() : personArr;
    }

    public static class ShopDataBean {
        @SerializedName("shop_name")
        public String shopName;
        public String money; //目标
        public String count; //业绩
        public String percent; //百分比
    }

    public static class UserDataBean {
        public String name;
        public String scaleCount; //量尺数
        public String newCountTarget; //新建客户数目标
        public String newCount; //新建客户数
        public String receiver; //回款
        public String prescaleCount; //预约量尺数
        public String scaleCountPercent; //量尺数百分比
        public String prescaleCountTarget; //预约量尺数目标
        public String contractTotal; //成交额
        public String receiverTarget; //回款目标
        public String orderTotal; //下单额
        public String scaleCountTarget; //量尺目标
        public String newCountPercent; //新建客户数百分比
        public String contractTotalPercent; //成交额百分比
        public String receiverPercent; //回款百分比
        public String orderTotalTarget; //下单额目标
        public String orderTotalPercent; //下单额百分比
        public String contractTotalTarget; //成交额目标
        public String prescaleCountPercent; //预约量尺数百分比
        public String picCount; //出图数
        public String picCountTarget; //出图目标
        public String picCountTargetPercent; //出图百分比
    }

    public static class ShopSelectBean {
        @SerializedName("shop_id")
        public String shopId;
        @SerializedName("shop_name")
        public String shopName;
    }

    public static class PersonDataBean {
        String Count; //数量
        String Target; //目标
        String Percent; //完成率
        public String type; //1 新建客户数、2预约量尺数、3业绩（万）、4回款（万）、5量尺数、6出图数、7下单（万）

        public double getPercentValue() {
            if (TextUtils.isEmpty(Percent)) return 0;
            return ParseUtils.parseDouble(Percent.replaceAll("%", "")) / 100;
        }

        public String getPercent() {
            if (TextUtils.isEmpty(Percent)) return "0.0%";
            if (!Percent.contains("%")) return Percent + "%";
            return Percent;
        }

        public String getTarget() {
            if (TextUtils.equals(type, "1") || TextUtils.equals(type, "2") ||
                    TextUtils.equals(type, "5") || TextUtils.equals(type, "6")) {
                return String.valueOf((int) ParseUtils.parseDouble(Target));
            }
            return Target;
        }

        public String getCount() {
            if (TextUtils.equals(type, "1") || TextUtils.equals(type, "2") ||
                    TextUtils.equals(type, "5") || TextUtils.equals(type, "6")) {
                return String.valueOf((int) ParseUtils.parseDouble(Count));
            }
            return Count;
        }
    }

}
